/** 普通用户权限接口二次封装 */
import axios from "../request";

/**
 * api-1.1 用户登录
 * @method post
 * @params uname,upwd
 */
export const userLoginServe = async function (uname, upwd) {
  let url = `/user/login`;
  let params = `uname=${uname}&upwd=${upwd}`;
  let res = await axios.post(url, params);
  return res.data;
};

/**
 * api-1.2 用户注册
 * @method post
 * @params uname,upwd,uphone,nickname
 */
export const userRegisterServe = async function (
  uname,
  upwd,
  uphone,
  nickname
) {
  let url = `/user/register`;
  let params = `uname=${uname}&upwd=${upwd}&uphone=${uphone}&nickname=${nickname}`;
  let res = await axios.post(url, params);
  return res.data;
};

/**
 * api-1.3 检查用户名是否已被占用
 * @method get
 * @params uname
 */
export const checkUnameServe = async function (uname) {
  let url = `/user/checkUname?uname=${uname}`;
  let res = await axios.get(url);
  return res.data;
};

/**
 * api-1.4 检查昵称是否已被占用
 * @method get
 * @params nickname
 */
export const checkNickServe = async function (nickname) {
  let url = `/user/checkNick?nickname=${nickname}`;
  let res = await axios.get(url);
  return res.data;
};

/**
 * api-2.1 查找所有文章的id、标题和概要及发布时间
 * @method get
 * @params page?
 */
export const articleServe = async function (page = 1, pagesize = 8) {
  let url = `/article/findAll?page=${page}&pagesize=${pagesize}`;
  let res = await axios.get(url);
  return res.data;
};

/**
 * api-2.2 文章详情
 * @method get
 * @params artid
 */
export const articleDetailServe = async function (artid) {
  let url = `/article/detail?artid=${artid}`;
  let res = await axios.get(url);
  return res.data;
};
